package com.example.java.designpattern.builder;

import com.example.java.designpattern.CompositeDivisor;
import com.example.java.designpattern.Divisor;

import java.util.ArrayList;
import java.util.Collection;

/**
 * @author zengty
 * @apiNote 组合模式建造者
 * @date 2024/8/29
 * @project study
 */
public class CompositeDivisorBuilder implements DivisorBuilder {

    private final Collection<Divisor> divisors;

    public CompositeDivisorBuilder() {
        divisors = new ArrayList<>();
    }

    public CompositeDivisorBuilder(Collection<Divisor> divisors) {
        this.divisors = divisors;
    }

    public CompositeDivisorBuilder addDivisor(Divisor divisor) {
        divisors.add(divisor);
        return this;
    }

    public static CompositeDivisorBuilder withDivisors(Collection<Divisor> divisors) {
        return new CompositeDivisorBuilder(divisors);
    }

    public CompositeDivisor build() {
        return new CompositeDivisor(divisors);
    }
}
